/**
 * 
 */
package com.ly.hotel.view.fragments.music;

import java.util.List;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridLayout;
import android.widget.ImageButton;
import android.widget.TextView;

import androidx.viewpager.widget.PagerAdapter;

import com.ly.hotel.R;
import com.ly.hotel.common.MyApplication;
import com.ly.hotel.model.MusicAlbumBean;
import com.ly.hotel.util.ImageUtil;


/**
 * @author jouson
 *专辑浏览界面
 */
public class MusicAlbumListAdapter extends PagerAdapter {

	private MusicActivity mContext;
	private List<List<MusicAlbumBean>> list;
    private MyApplication app;
	private LayoutInflater inflater;
	private MusicActivity context;

	public MusicAlbumListAdapter(MusicActivity c, List<List<MusicAlbumBean>> hotInfos) {
		super();
		this.mContext = c;
		this.list = hotInfos;
		inflater = LayoutInflater.from(mContext);
	}


	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == object;
	}

	@Override
	public Object instantiateItem(ViewGroup container, final int position) {
		View view = inflater.inflate(R.layout.music_pager_item,container,false);
		int round = mContext.getResources().getDimensionPixelOffset(R.dimen.px123);
		container.addView(view);
		GridLayout gdl = (GridLayout) view.findViewById(R.id.episodes_gridlayout);

		List<MusicAlbumBean> vvl = list.get(position);
		for (final MusicAlbumBean vv:vvl) {
            final String name = vv.getAlbumName();
			View tmpBtn = inflater.inflate(R.layout.music_album_list_item, null);

			ImageButton albumImageBt = (ImageButton) tmpBtn.findViewById(R.id.singerImage);
            TextView albumNameText = (TextView) tmpBtn.findViewById(R.id.singerName);
            albumNameText.setText(name);
            ImageUtil.displayImage_Round(mContext, app.getHostResUrl() + vv.getImg(), albumImageBt,round);

			albumImageBt.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					mContext.albumGridViewProcess(vv);
				}
			});
			gdl.addView(tmpBtn);
		}
		return view;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView((View) object);
	}
}
